<?php
class Z1usersController extends AppController {

	var $name = 'Z1users';

	function index($khoa_id=null) {
		$this->Z1user->recursive = 0;
		$this->set('z1users', $this->paginate(array('Z1user.khoa_id'=>$khoa_id)));
        $this->set(compact('khoa_id'));
	}
    function search(){
        $this->layout='search';
        //sua ds cac truogn can tim, cai nay phai khop voi cac o tim kiem tren view
        $column = array('Z1user.maso',
                        'Z1user.hoten',
                        'Z1user.tenchidoan',
                        );
        $value = $this->params['pass'];
        //pr($value);exit;
        //$conditions[]=array();
        for($i=0;$i<count($column);$i++){
            if($value[$i]!="null"){
                
                        $conditions[] = array($column[$i].' Like'=>'%'.$value[$i].'%');   //check text input
                
            }
        }
        if(!empty($conditions)){
            $results=$this->Z1user->find('all',array('conditions'=>$conditions));    
        }else $results=$this->Z1user->find('all');
        
        $this->set('results', $results);
    }
	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid z1user', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('z1user', $this->Z1user->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Z1user->create();
			if ($this->Z1user->save($this->data)) {
				$this->Session->setFlash(__('The z1user has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The z1user could not be saved. Please, try again.', true));
			}
		}
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid z1user', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Z1user->save($this->data)) {
				$this->Session->setFlash(__('The z1user has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The z1user could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Z1user->read(null, $id);
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for z1user', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Z1user->delete($id)) {
			$this->Session->setFlash(__('Z1user deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Z1user was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
